<?php
/**
 * Created by PhpStorm.
 * User: fengzi
 * Date: 2019/6/3
 * Time: 14:34
 */

namespace app\vehicle\logic;
use app\vehicle\model\Resume;
use app\vehicle\model\ResumeLog;
use app\common\model\ResumeCate;
class resumeLogic
{
    public function getResumeCate(){
        $list = ResumeCate::where('status','eq',1)->select();
        return $list;
    }
    public function getResumeList($data){
        $where[] = ['status','eq',1];
        $data['cate_id'] && $where[] = ['cate_id','eq',$data['cate_id']];
        $list = Resume::where($where)->order('create_time desc')->page($data['page'],100)->select();
        return $list;
    }
    public function getResumeInfo($data){
        if(!$data['id']){
            $data['id'] = Resume::where('cate_id','eq',2)->value('id');
        }
        Resume::where('id', 'eq', $data['id'])->setInc('read_num', 1);
        $info = Resume::get($data['id']);
        $info['content'] = str_replace('/ueditor/php/upload/image',config('database.img_url').'/ueditor/php/upload/image',$info['content']);
        $info['content'] = htmlspecialchars_decode($info['content']);
        return $info;
    }

    public function getNoticeInfo($data){
        $data['id'] = Resume::where('cate_id','eq',3)->order('id desc')->value('id');
        Resume::where('id', 'eq', $data['id'])->setInc('read_num', 1);
        $info = Resume::get($data['id']);
        return $info;
    }

    public function setResume($data,$user_id){
        $check = ResumeLog::where('user_id','eq',$user_id)->where('rid','eq',$data['id'])->count();
        if($check){
            return '已报名';
        }
        $num = ResumeLog::where('rid','eq',$data['id'])->count();
        $info = Resume::get($data['id']);
        if($num>=$info['number']){
            return '活动人数已满';
        }
        $insert['user_id'] = $user_id;
        $insert['rid'] = $data['id'];
        $insert['create_time'] = time();
        ActivityLog::insert($insert);
        return 1;
    }
}